home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Table / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  9.6 KB  |  374 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 1 $ 
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Table.hpp"
  11.  
  12. // ----- TablePart Includes -----
  13.  
  14. #ifndef BINDING_K
  15. #include "Binding.k"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef FRAME_H
  23. #include "Frame.h"
  24. #endif
  25.  
  26. #ifndef PROXY_H
  27. #include "Proxy.h"
  28. #endif
  29.  
  30. #ifndef SELECTION_H
  31. #include "Selection.h"
  32. #endif
  33.  
  34. #ifndef SOM_ODFExamples_ODFTableEmbeddedFramesIterator_xh
  35. #include "SOMIter.xh"
  36. #endif
  37.  
  38. #ifndef LINKING_H
  39. #include "Linking.h"
  40. #endif
  41.  
  42. #ifndef CONTENT_H
  43. #include "Content.h"
  44. #endif
  45.  
  46. // ----- Part Layer -----
  47.  
  48. #ifndef FWFRAME_H
  49. #include "FWFrame.h"
  50. #endif
  51.  
  52. #ifndef FWABOUT_H
  53. #include "FWAbout.h"
  54. #endif
  55.  
  56. #ifndef FWFCTCLP_H
  57. #include "FWFctClp.h"
  58. #endif
  59.  
  60. #ifndef FWPRTITE_H
  61. #include "FWPrtIte.h"
  62. #endif
  63.  
  64. #ifndef FWDRCMD_H
  65. #include "FWDrCmd.h"
  66. #endif
  67.  
  68. #ifndef FWUTIL_H
  69. #include "FWUtil.h"
  70. #endif
  71.  
  72. // ----- OS Layer -----
  73.  
  74. #ifndef FWACQUIR_H
  75. #include "FWAcquir.h"
  76. #endif
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWMENU_H
  83. #include "FWMenu.h"
  84. #endif
  85.  
  86. #ifndef FWPOINT_H
  87. #include "FWPoint.h"
  88. #endif
  89.  
  90. #ifndef FWRECT_H
  91. #include "FWRect.h"
  92. #endif
  93.  
  94. #ifndef FWSUSINK_H
  95. #include "FWSUSink.h"
  96. #endif
  97.  
  98. #ifndef FWODGEOM_H
  99. #include "FWODGeom.h"
  100. #endif
  101.  
  102. #ifndef FWBARRAY_H
  103. #include "FWBArray.h"
  104. #endif
  105.  
  106. #ifndef FWCFMRES_H
  107. #include "FWCFMRes.h"
  108. #endif
  109.  
  110. // ----- Foundation Layer -----
  111.  
  112. #ifndef FWSTRING_H
  113. #include "FWString.h"
  114. #endif
  115.  
  116. #ifndef FWEXCDEF_H
  117. #include "FWExcDef.h"
  118. #endif
  119.  
  120. // ----- OpenDoc Includes -----
  121.  
  122. #ifndef FWODTYPS_H
  123. #include "FWODTyps.h"
  124. #endif
  125.  
  126. #ifndef SOM_ODArbitrator_xh
  127. #include <Arbitrat.xh>
  128. #endif
  129.  
  130. #ifndef SOM_ODMenuBar_xh
  131. #include <MenuBar.xh>
  132. #endif
  133.  
  134. #ifndef SOM_ODShape_xh
  135. #include <Shape.xh>
  136. #endif
  137.  
  138. #ifndef SOM_Module_OpenDoc_StdProps_defined
  139. #include <StdProps.xh>
  140. #endif
  141.  
  142. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  143. #include <StdTypes.xh>
  144. #endif
  145.  
  146. #ifndef SOM_ODStorageUnit_xh
  147. #include <StorageU.xh>
  148. #endif
  149.  
  150. #ifndef SOM_ODTransform_xh
  151. #include <Trnsform.xh>
  152. #endif
  153.  
  154. #ifndef SOM_ODSession_xh
  155. #include <ODSessn.xh>
  156. #endif
  157.  
  158. //========================================================================================
  159. // RunTime Info
  160. //========================================================================================
  161.  
  162. #ifdef FW_BUILD_MAC
  163. #pragma segment odfTable
  164. #endif
  165.  
  166. FW_DEFINE_AUTO(CTablePart)
  167.  
  168. //========================================================================================
  169. //    class CTablePart
  170. //========================================================================================
  171.  
  172. //----------------------------------------------------------------------------------------
  173. //    CTablePart::CTablePart
  174. //----------------------------------------------------------------------------------------
  175.  
  176. CTablePart::CTablePart(ODPart* odPart) :
  177.     FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID),
  178.     fTableLinkManager(NULL),
  179.     fLinksRegistered(false)
  180. {
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    CTablePart::~CTablePart
  185. //----------------------------------------------------------------------------------------
  186.  
  187. CTablePart::~CTablePart()
  188. {
  189. }
  190.  
  191. //----------------------------------------------------------------------------------------
  192. //    CTablePart::Initialize
  193. //----------------------------------------------------------------------------------------
  194.  
  195. void CTablePart::Initialize(Environment* ev)
  196. {
  197.     // ----- Call Inherited Initialize -----
  198.     FW_CEmbeddingPart::Initialize(ev);
  199.  
  200.     // ----- Register Presentation -----
  201.     fTablePresentation = RegisterPresentation(ev, "Apple:Presentation:ODFTable", true, FW_NEW(CTableSelection, (ev, this, fTableContent)));
  202.     
  203.     // ----- Build Table menu -----
  204. #ifdef FW_BUILD_WIN
  205.     // [HLX] Temporary embed menu for windows
  206.     WinAddEmbedMenu(ev, GetMenuBar(ev));
  207. #endif
  208.  
  209.     FW_DO_NOT_DEAD_STRIP(FW_CToggleItem);
  210.     GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    CTablePart::NewFrame
  215. //----------------------------------------------------------------------------------------
  216.  
  217. FW_CFrame* CTablePart::NewFrame(Environment* ev, 
  218.                                 ODFrame* odFrame, 
  219.                                 FW_CPresentation* presentation,
  220.                                 FW_Boolean fromStorage)
  221. {
  222.     FW_UNUSED(fromStorage);
  223.  
  224.     return FW_NEW(CTableFrame, (ev, odFrame, presentation, this, fTableContent));
  225. }
  226.  
  227. //----------------------------------------------------------------------------------------
  228. //    CTablePart::NewPartContent
  229. //----------------------------------------------------------------------------------------
  230.  
  231. FW_CContent* CTablePart::NewPartContent(Environment* ev)
  232. {
  233.     fTableContent = FW_NEW(CTableContent, (ev, this));
  234.     return fTableContent;
  235. }
  236.  
  237. //========================================================
  238. // ADDITIONS FOR LINKING SUPPORT
  239. //========================================================
  240.  
  241. //----------------------------------------------------------------------------------------
  242. //    CTablePart::PartChanged
  243. //----------------------------------------------------------------------------------------
  244. void CTablePart::PartChanged(Environment* ev)
  245. {
  246.     fTablePresentation->ContentUpdated(ev);
  247.  
  248.     //--- Update affected link sources ---
  249.     fTableLinkManager->UpdateLinkSource(ev, kODUnknownUpdate);
  250. }
  251.  
  252. //----------------------------------------------------------------------------------------
  253. // CTablePart::RegisterSubscribers
  254. //----------------------------------------------------------------------------------------
  255.  
  256. void CTablePart::RegisterSubscribers(Environment* ev)
  257. {
  258.     //--- Check for links that need to be registered for automatic updates
  259.     if (!fLinksRegistered)    // only want to do this once!
  260.     {
  261.         fTableLinkManager->RegisterLinks(ev);
  262.         fLinksRegistered = true;
  263.     }
  264. }
  265.  
  266. //----------------------------------------------------------------------------------------
  267. // CTablePart::ShowLinkInfo
  268. //----------------------------------------------------------------------------------------
  269.  
  270. FW_Boolean CTablePart::ShowLinkInfo(Environment* ev, FW_CFrame* frame)
  271. {
  272.     return fTableLinkManager->ShowLinkInfo(ev, frame->GetActiveFacet(ev));
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    CTablePart::IsLinkSelected
  277. //----------------------------------------------------------------------------------------
  278.  
  279. FW_Boolean CTablePart::IsLinkSelected(Environment* ev)
  280. {
  281.     /* for now, return TRUE if a link's cell is selected */
  282.     if (fTableLinkManager->GetSelectedLinkSource(ev) != NULL)
  283.         return true;
  284.     else if (fTableLinkManager->GetSelectedLinkDest(ev) != NULL)
  285.         return true;
  286.  
  287.     return false;
  288. }
  289.  
  290. //----------------------------------------------------------------------------------------
  291. // CTablePart::DoMenu
  292. //----------------------------------------------------------------------------------------
  293.  
  294. FW_Boolean CTablePart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
  295. {
  296.     FW_Boolean menuHandled = true;
  297.     if (theMenuEvent.GetCommandID(ev) == kODCommandAbout)
  298.         ::FW_About(ev, this, kAbout);
  299.     else
  300.         menuHandled = false;
  301.         
  302.     return menuHandled;
  303. }
  304. //----------------------------------------------------------------------------------------
  305. //    CTablePart::ChangeFrameStatus
  306. //----------------------------------------------------------------------------------------
  307.  
  308. void CTablePart::ChangeFrameStatus(Environment* ev, const CCell& cell, ODLinkStatus newStatus)
  309. {
  310.     CTableProxy* proxy = fTableContent->CellToProxy(cell);
  311.     if (proxy)
  312.         proxy->ChangeLinkStatus(ev, newStatus);
  313. }
  314.  
  315. //----------------------------------------------------------------------------------------
  316. //    CTablePart::AboutToClearCell
  317. //----------------------------------------------------------------------------------------
  318. void CTablePart::AboutToClearCell(Environment* ev, const CCell& cell)
  319. {
  320.     //-- Break affected links --
  321.     fTableLinkManager->BreakExistingLinks(ev, cell);
  322. }
  323.  
  324. //----------------------------------------------------------------------------------------
  325. //    CTablePart::ProxyMoved
  326. //----------------------------------------------------------------------------------------
  327. void CTablePart::ProxyMoved(Environment* ev,
  328.                             const CCell& fromCell,
  329.                             const CCell& toCell)
  330. {
  331.     //-- Adjust affected links --
  332.     fTableLinkManager->MoveExistingLinks(ev, fromCell, toCell);
  333. }
  334.  
  335. //----------------------------------------------------------------------------------------
  336. //    CTablePart::GetTableSelection
  337. //----------------------------------------------------------------------------------------
  338. CTableSelection* CTablePart::GetTableSelection(Environment* ev)
  339. {
  340.     return (CTableSelection*) fTablePresentation->GetSelection(ev);
  341. }
  342.  
  343. //----------------------------------------------------------------------------------------
  344. //    CTablePart::DoAdjustMenus
  345. //----------------------------------------------------------------------------------------
  346.  
  347. FW_Boolean CTablePart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  348. {
  349.     FW_UNUSED(isRoot);
  350.  
  351.     if (hasMenuFocus)
  352.     {
  353.         //--- Set up the Part Info menu item ---
  354.         if (this->IsLinkSelected(ev))
  355.         {
  356.             menuBar->SetItemString(ev, kODCommandGetPartInfo, FW_CString32("Link Info"));
  357.             menuBar->EnableCommand(ev, kODCommandGetPartInfo, true);
  358.         }
  359.     }
  360.     
  361.     return false;
  362. }
  363.  
  364. //----------------------------------------------------------------------------------------
  365. //    CTablePart::NewLinkManager
  366. //----------------------------------------------------------------------------------------
  367.  
  368. FW_CLinkManager* CTablePart::NewLinkManager(Environment* ev)    // Override
  369. {
  370.     CTableLinkManager* linkMgr = FW_NEW (CTableLinkManager, (ev, this, fTableContent));
  371.     fTableLinkManager = linkMgr;
  372.     return linkMgr;
  373. }
  374.